package com.senjoeson.teamfriends.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.senjoeson.teamfriends.R;
import com.senjoeson.teamfriends.adapter.TeamMessageAdapter;
import com.senjoeson.teamfriends.base.BaseFragment;
import com.senjoeson.teamfriends.bean.FriendMessage;
import com.senjoeson.teamfriends.bean.User;
import com.senjoeson.teamfriends.utils.ALog;

import java.util.List;

import butterknife.BindView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * @author senjoeson
 * @date 2018/4/25
 */

public class HobbiesFragment extends BaseFragment {

    @BindView(R.id.recyclyerview)
    RecyclerView mRecyclyerview;


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_friend;
    }

    @Override
    protected void initData() {
        mRecyclyerview.setLayoutManager(new LinearLayoutManager(getContext()));
        final TeamMessageAdapter teamMessageAdapter = new TeamMessageAdapter(getActivity());
        mRecyclyerview.setAdapter(teamMessageAdapter);
        BmobQuery<FriendMessage> friendMessageBmobQuery = new BmobQuery<>();
        User currentUser = BmobUser.getCurrentUser(User.class);
        friendMessageBmobQuery.addWhereNotEqualTo("user_id",currentUser.getObjectId());
        friendMessageBmobQuery.addWhereContainedIn("hobby_name", currentUser.getHobbies());
        friendMessageBmobQuery.findObjects(new FindListener<FriendMessage>() {
            @Override
            public void done(List<FriendMessage> list, BmobException e) {
                if (list != null && list.size() > 0) {
                    teamMessageAdapter.setDatas(list);
                    teamMessageAdapter.notifyDataSetChanged();
                } else {
                    ALog.d("Empty Data");
                }
            }
        });


    }

    @Override
    protected void initListener() {

    }

}
